/* 
 * Copyright (c) 2022, CENTRIN.CIYUN.LTD. All rights reserved.
 */
package com.cory.module.oplog.controller;

import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.cory.boot.base.BaseController;
import com.cory.module.oplog.domain.entity.Oplog;
import com.cory.module.oplog.service.OplogService;
import com.github.pagehelper.PageInfo;

/**
 * @author xiongcong
 * @date 2022-01-12
 */
@Controller
@RequestMapping("admin/oplog")
public class OplogController extends BaseController {
    @Autowired
    private OplogService oplogService;

    @RequestMapping("list/object")
    public String object(Oplog param, Model model) {
        assertNotNull(param.getObjectAlias(), param.getObjectId());
        
        super.startPage();
        List<Oplog> list = oplogService.list(param);
        model.addAttribute("page", new PageInfo<>(list));
        
        List<Long> logIds = list.stream().map(i -> i.getId()).collect(Collectors.toList());
        model.addAttribute("attributes", oplogService.listAttributes(logIds));
        
        model.addAttribute("param", param);
        return "admin/oplog/list.object";
    } 
    
    @RequestMapping("list")
    public String list(Oplog param, Model model) {
        
        super.startPage();
        List<Oplog> list = oplogService.list(param);
        model.addAttribute("page", new PageInfo<>(list));
        
        List<Long> logIds = list.stream().map(i -> i.getId()).collect(Collectors.toList());
        model.addAttribute("attributes", oplogService.listAttributes(logIds));
        
        model.addAttribute("param", param);
        return "admin/oplog/list";
    } 
}
